const Router = require('koa-router')
const router = new Router({ prefix: '/' })
const u = require('../api')

router.get('/', async (ctx) => {
  ctx.response.status = 200
  ctx.config.nav[0].checked = true
  ctx.config.title = '达州市八益驾校有限责任公司-官网'
  ctx.config.description = '达州市八益驾校有限责任公司经四川省道路运输管理局批准成立的一所省级一类综合驾校，专门从事机动车驾驶员培训，是达州市交警支队机动车驾驶员科目二、科目三考试基地。'
  ctx.config.keyword = '达州八益驾校,达州八一驾校,达州驾校,达州市驾校,达州驾校价格,达州八益驾校网上报名,达州学车'
  // 考场设施
  const facilities = [{
    id: 1,
    title: '考试场地',
    src: `${ctx.config.host}/imgs/facilities1.png`,
  }, {
    id: 2,
    title: 'C1-C2车型',
    src: `${ctx.config.host}/imgs/facilities2.png`,
  }, {
    id: 3,
    title: 'B2车型',
    src: `${ctx.config.host}/imgs/facilities3.png`,
  }, {
    id: 4,
    title: 'B1-A1-A3车型（校车接送）',
    src: `${ctx.config.host}/imgs/facilities4.png`,
  }, {
    id: 5,
    title: '模拟教室',
    src: `${ctx.config.host}/imgs/facilities5.png`,
  }, {
    id: 6,
    title: '科目一理论考试',
    src: `${ctx.config.host}/imgs/facilities6.png`,
  }]
  // 新闻动态
  var news = await u.getNewsList({
    category: 'BYJX-QYXW',
    keyword: '',
    pageNum: 1,
    pageSize: 5
  })
  news.result.list.filter(item => {
    item.href = `${ctx.config.host}/qyxw/${item.id}.html`
  })
  // 企业新闻
  var qyxw = await u.getNewsList({
    category: 'BYJX-QYXW',
    keyword: '',
    pageNum: 1,
    pageSize: 6
  })
  qyxw.result.list.filter(item => {
    item.href = `${ctx.config.host}/qyxw/${item.id}.html`
    item.publishedTimeNow = item.publishedTime ? item.publishedTime.split(' ')[0] : ''
  })
  // 行业动态
  var hydt = await u.getNewsList({
    category: 'BYJX-HYDT',
    keyword: '',
    pageNum: 1,
    pageSize: 6
  })
  hydt.result.list.filter(item => {
    item.href = `${ctx.config.host}/hydt/${item.id}.html`
    item.publishedTimeNow = item.publishedTime ? item.publishedTime.split(' ')[0] : ''
  })
  await ctx.render('index.ejs', {
    config: ctx.config,
    facilities,
    honor: ctx.config.honor,
    qyxwList: qyxw.result.list,
    hydtList: hydt.result.list,
    newsList: news.result.list
  })
})

module.exports = router